package lib.bone.admin.controller.nepu.fix;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lib.bone.audit.workload.dao.NepuWorkloadDAO;
import lib.bone.audit.workload.domain.NepuWorkload;
import lib.bone.audit.workload.service.NepuWorkloadService;
import lib.bone.common.constant.ResponseCodeConst;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.flow.domain.entity.FlowTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("nepu/workloads/award/fix")
@Slf4j
@Api(tags = "教学科研获奖工作量记录修复")
public class AwardWorkloadFixController {

    @Autowired
    NepuWorkloadService nepuWorkloadService;

    @PostMapping("{field}")
    @ApiOperation(value = "修复字段内容",notes = "目前只支持修复 dictName")
    public ResponseDTO<Object> fixAwardField(@PathVariable("field") String field){
        log.info(field);
        if (field.equals("Award")){
            // 全量查询
            List<NepuWorkload> workloads = nepuWorkloadService.getAll();
            workloads.forEach(workload->{
                nepuWorkloadService.buildAwardDictName(workload);
            });
            return ResponseDTO.succMsg("成功执行");
        }else {
            return ResponseDTO.wrap(ResponseCodeConst.SERVICE_UNAVAILABLE);
        }
    }
}
